<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>管理员</el-breadcrumb-item>
      <el-breadcrumb-item>文章审核</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card class="box-card">
      <el-table :data="articles" border style="width: 100%">
        <el-table-column type="index" label="序号" width="60" align="center">
        </el-table-column>
        <el-table-column
          prop="title"
          label="文章标题"
          width="150"
          align="center"
        >
        </el-table-column>
        <el-table-column label="作者" width="120" align="center">
          <template slot-scope="scope">
            <div>
              {{ scope.row.user.username }}
            </div>
          </template>
        </el-table-column>
        <el-table-column
          prop="readNums"
          label="阅读量"
          align="center"
          width="120"
        >
        </el-table-column>
        <el-table-column
          prop="likeNums"
          label="点赞量"
          align="center"
          width="120"
        >
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="发布时间"
          width="150"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="updateTime"
          label="更新时间"
          width="150"
          align="center"
        >
        </el-table-column>

        <!-- <el-table-column
          prop="isDelete"
          label="是否删除"
          width="100"
          align="center"
        >
          <template slot-scope="scope">
            <div>
              {{ scope.row.isDelete === 0 ? "未删除" : "已删除" }}
            </div>
          </template>
        </el-table-column> -->
        <!-- <el-table-column label="目前状态" width="140" align="center">
          <template>
            <div>
              <el-select v-model="value" placeholder="请选择">
                <el-option
                  v-for="item in options"
                  :key="item.value"
                  :label="item.label"
                  :value="item.value"
                >
                </el-option>
              </el-select>
            </div>
          </template>
        </el-table-column> -->
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              size="mini"
              type="primary"
              @click="seeArticleDetail(scope.row)"
            >
              查看
            </el-button>
            <el-button
              size="mini"
              type="primary"
              @click="showPassIdentifyDialogVisible(scope.row)"
            >
              通过审核
            </el-button>
            <el-dialog
              title="提示"
              :visible.sync="passIdentifyDialogVisible"
              width="30%"
            >
              <span>确定通过文章认证？</span>
              <span slot="footer" class="dialog-footer">
                <el-button @click="passIdentifyDialogVisible = false"
                  >取 消</el-button
                >
                <el-button type="primary" @click="confirmPass">确 定</el-button>
              </span>
            </el-dialog>
            <el-button
              size="mini"
              type="primary"
              @click="showUnPassIdentifyDialogVisible(scope.row)"
              style="margin-left:10px"
            >
              不通过审核
            </el-button>
            <el-dialog
              title="提示"
              :visible.sync="unpassIdentifyDialogVisible"
              width="30%"
            >
              <span>确定不通过文章认证？</span>
              <span slot="footer" class="dialog-footer">
                <el-button @click="unpassIdentifyDialogVisible = false"
                  >取 消</el-button
                >
                <el-button type="primary" @click="confirmUnPass"
                  >确 定</el-button
                >
              </span>
            </el-dialog>
          </template>
        </el-table-column>
      </el-table>
    </el-card>

    <el-dialog :visible.sync="articleInfoVisible" width="50%">
      <h1 style="text-align:center">查看课程具体资源信息</h1>
      <el-form :model="form">
        <el-form-item label="文章标题" :label-width="formLabelWidth">
          <el-input :value="form.title" autocomplete="off" disabled></el-input>
        </el-form-item>
        <el-form-item label="文章封面" :label-width="formLabelWidth">
          <img :src="form.coverUrl" alt="" width="50%" />
        </el-form-item>
        <el-form-item label="文章内容" :label-width="formLabelWidth">
          <!-- 富文本编辑器 -->
          <editor-bar
            class="list-editor"
            :isClear="isClear"
            :newValue="form.content"
          ></editor-bar>
        </el-form-item>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
import { ReqGetArticleByStatus, ReqCheckArticle } from "../../request/index.js";
import EditorBar from "../../components/wangEnduit";

export default {
  components: { EditorBar },
  data() {
    return {
      articleInfoVisible: false,
      articles: [],
      form: {},
      formLabelWidth: "120px",
      isClear: false,
      page: 1,

      passIdentifyDialogVisible: false,
      unpassIdentifyDialogVisible: false,
      temRow: {},
    };
  },
  methods: {
    seeArticleDetail(row) {
      this.articleInfoVisible = true;
      console.log(row);
      this.form = row;
    },
    showPassIdentifyDialogVisible(row) {
      this.passIdentifyDialogVisible = true;
      this.temRow = row;
    },
    showUnPassIdentifyDialogVisible(row) {
      this.unpassIdentifyDialogVisible = true;
      this.temRow = row;
    },
    confirmPass() {
      console.log(this.temRow);
      this.passIdentifyDialogVisible = false;
      ReqCheckArticle({
        articleId: this.temRow.id,
        status: 3,
      }).then((res) => {
        if ((res.msg = "成功")) {
          this.$message({
            showClose: true,
            message: "操作成功",
            type: "success",
          });
        } else {
          this.$message({
            showClose: true,
            message: "操作失败",
            type: "warning",
          });
        }
        this.getArticles();
      });
    },
    confirmUnPass() {
      console.log(this.temRow);
      this.unpassIdentifyDialogVisible = false;
      ReqCheckArticle({
        articleId: this.temRow.id,
        status: 2,
      }).then((res) => {
        if ((res.msg = "成功")) {
          this.$message({
            showClose: true,
            message: "操作成功",
            type: "success",
          });
        } else {
          this.$message({
            showClose: true,
            message: "操作失败",
            type: "warning",
          });
        }
        this.getArticles();
      });
    },
    getArticles() {
      ReqGetArticleByStatus({
        num: 4,
        begin: this.page,
        identityStatus: 1,
      }).then((res) => {
        this.articles = res.data.records;
        console.log(res.data);
        // this.totalPage = res.data.total;
        // let articleId = res.data.records.id;
      });
    },
  },
  created() {
    ReqGetArticleByStatus({
      num: 4,
      begin: this.page,
      identityStatus: 1,
    }).then((res) => {
      this.articles = res.data.records;
      console.log(res.data);
    });
  },
};
</script>

<style scoped></style>
